//
//  TimeStapView.m
//  wtshoppingcite
//
//  Created by Baojia-LC on 14/11/13.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "TimeStapView.h"

@implementation TimeStapView

-(id)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}

-(void)initTimeTitleName:(NSArray*)itemNames step:(NSString*)status{

    UIImageView * line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 9, CGRectGetWidth(self.frame), 1)];
    line.backgroundColor = MAIN_BLUE_COLOR;
    [self addSubview:line];
    
    _itemNames = itemNames;
    int count = [itemNames count];
    float width = CGRectGetWidth(self.frame) / count;
    float height = CGRectGetHeight(self.frame);

    for (int i = 0; i < count; i ++) {
        
        UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(width * i,5 , width, height - 3)];
        [btn setTitle:[itemNames objectAtIndex:i] forState:UIControlStateNormal];
        btn.tag = 1000 + i;
        btn.titleEdgeInsets = UIEdgeInsetsMake(10, 0, 0, 0);
        [btn setTitleColor:MAIN_GRAY_COLOR forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
        
        UIView* corLview = [[UIView alloc] initWithFrame:CGRectMake((width - 10)/2, 0, 10, 10)];
        corLview.backgroundColor = MAIN_GRAY_COLOR;
        corLview.layer.cornerRadius = 5;
        corLview.clipsToBounds = YES;
        corLview.tag = 2000 +i;
        [btn addSubview:corLview];
        
        if(i<=status.intValue){
            [btn setTitleColor:MAIN_BLUE_COLOR forState:UIControlStateNormal];
            corLview.backgroundColor = MAIN_BLUE_COLOR;
        }
        
        [self addSubview:btn];
    }
}

-(void)setStepStatus:(NSString*)step{
    
    for(int i = 0;i<_itemNames.count;i++){
        UIButton* btn = (UIButton*)[self viewWithTag:1000+i];
        UIView* corLview = [btn viewWithTag:2000+i];
        if(i<step.integerValue){

            [btn setTitleColor:MAIN_BLUE_COLOR forState:UIControlStateNormal];
            corLview.backgroundColor = MAIN_BLUE_COLOR;
        }else{
            
            [btn setTitleColor:MAIN_GRAY_COLOR forState:UIControlStateNormal];
            corLview.backgroundColor = MAIN_GRAY_COLOR;
        }
    }
    
}

@end
